CC  = gcc
CXX = g++
RM  = rm
MV  = mv
CP  = cp
EXE = compiler
OBJ = main.o lex.yy.o yy.o common.o display.o nlist.o sizer.o prescan.o \
      item.o pnode.o dlink.o flink.o pcoder.o const.o pcoder1.o pcoder2.o \
	  pcoder4.o pcoder5.o pcoder6.o pcoder7.o pcoder8.o popt.o popt1.o popt2.o popt3.o \
	  popt4.o popt5.o popt6.o \
	  pic16e_asm.o pic16e.o pic16e_reg.o pic16e0.o pic16e1.o pic16e2.o pic16e3.o pic16e4.o \
	  pic16e5.o pic16e6.o pic16e7.o pic16e8.o pic16e9.o pic16e10.o pic16e11.o pic16e12.o pic16e13.o \
	  option.o

#OPTIONS= -c -Os -Wall
OPTIONS= -c -g

${EXE}: ${OBJ} yy.h makefile
	${CXX} -static ${OBJ} -o ${EXE}
	${CP} ${EXE} $(BUILD_DIR)

%.o: %.c yy.h makefile
	${CC} ${OPTIONS} $<

%.o: %.cpp yy.h makefile
	${CXX} ${OPTIONS} $<
	
%.o: ./p16e/%.cpp yy.h makefile
	$(CXX) $(OPTIONS) $<

lex.yy.c: yy.l yy.h makefile
	flex yy.l

yy.h: yy.y makefile
	bison -d yy.y -o yy.c

yy.c: yy.y makefile
	bison -d yy.y -o yy.c

e1: ${EXE} makefile
	./compiler e1.c > s

e3: ${EXE} makefile
	./compiler -riscv e3.c -o e3.S
	
clean:
	$(RM) *.o
	$(RM) yy.h
	$(RM) yy.c
	$(RM) lex.yy.c
	$(RM) $(EXE)
	${RM} yy.output
	${RM} yy.tab.c


test:
	autotest -riscv -t /root/compiler/testcases/2023/functional /root/compiler
